new Vue({
  components: {},
  el: '#service',
  data: {
    nowData: [],
    beforeData: [],
    nextData: {},
    nextTitle: "",
    disabledbefore: false,
    disablednext: false,
    beforeid: 0,//上一页的id
    nextid: 0,//下一页的id
    id: 0,//该页的id
  },
  mounted() {
    var that = this;
    this.id = get('id');
    //获取当前id的数据和下一条数据
    axios
      .get("http://dl.sword.ink:2334/product/" + this.id)
      .then((res) => {
        that.nowData = JSON.parse(JSON.stringify(res.data.data[0]));
        // 如果获取到的数据量小于2的话，则将下一篇的按钮文本换为没有了
        if (res.data.data.length < 2) {
          that.nextTitle = "没有了";
          that.disablednext = true;
        } else {
          that.nextTitle = "下一篇";
        }
        //将下条数据的id存到nextid中
        this.nextid = res.data.data[1].id;
      });
    //获取上两条数据
    axios
      .get("http://dl.sword.ink:2334/productc/" + this.id + '&-1')
      .then((res) => {
        //如果当前数据之前没有数据了，那么设置上一条的按钮为不可用
        if (res.data.data.length < 1) {
          this.disabledbefore = true
        }
        that.nowData = JSON.parse(JSON.stringify(res.data.data[0]));
        //将上条数据的id存到beforeid中
        this.beforeid = res.data.data[0].id;
      });
  },
  methods: {
    toBeforeNew() {
      document.location.href = './service.html?id=' + this.beforeid
    },
    toNextNew() {
      document.location.href = './service.html?id=' + this.nextid
    },
  },
})
//   获取id
function get(par) {
  //获取bai当前URL
  var local_url = window.location.href;

  //截取get字符串
  var getstr = local_url.substr(local_url.indexOf('?') + 1)

  //解析du成get数组
  var get = getstr.split('&')

  //查找要找的参数（zhipar）
  for (var i in get) {
    if (get[i].indexOf(par + '=') >= 0) {
      return get[i].replace(par + '=', '');
    }
  }
  //如果找不到返回daofalse
  return false;
}
